﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AlertSystem.PluggableModules;
using System.Diagnostics;
using AlertSystem.Business;
using System.Threading;
using System.Reflection;

namespace AlertSystem.UI
{
    class TrackingService : WorkingBaseTimer
    {
        protected override int DUETIME { get { return 30000; } }

        protected override void LoopWorking()
        {
            string serviceName = System.Configuration.ConfigurationManager.AppSettings["TrackingServiceName"];
            try
            {
                using (Mutex.OpenExisting("SAMI.SMSROUTER.37F6E30A-76ED-4E66-84BE-32D11C9BD580"))
                {

                }
            }
            catch
            {
                Warning_Message.Insert("database", Settings.AppSetting.SystemID, string.Format("{0}: {1} is not running", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"), serviceName));
            }
            //string serviceName = System.Configuration.ConfigurationManager.AppSettings["TrackingServiceName"];
            //string machineName = System.Configuration.ConfigurationManager.AppSettings["TrackingMachineName"];
            //string assemblyGuid = System.Configuration.ConfigurationManager.AppSettings["TrackingAssemblyGuid"];
            //if (!Process.GetProcessesByName(serviceName, machineName).Any(
            //    p => Assembly.LoadFrom(p.MainModule.FileName)
            //        .GetCustomAttributes(typeof(GuidAttribute), false)
            //        .Any(attr => ((GuidAttribute)attr).Value.Equals(assemblyGuid, StringComparison.CurrentCultureIgnoreCase))
            //))
            //{
            //    Warning_Message.Insert("database", "emarketing", string.Format("{0}: {1} is not running", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"), serviceName));
            //}
        }
    }
}
